<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	
	<SCRIPT src="../../../NCProjectWeb/js/jquery.min.js" type="text/javascript"></SCRIPT>
    <SCRIPT src="../../../NCProjectWeb/js/moment.js" type="text/javascript"></SCRIPT>
    <SCRIPT src="../../../NCProjectWeb/js/bootstrap-datetimepicker.js" type="text/javascript"></SCRIPT>
    <SCRIPT src="../../../NCProjectWeb/js/bootstrap-datetimepicker.ru.js" type="text/javascript"></SCRIPT>
    <link href="../../../NCProjectWeb/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../../NCProjectWeb/css/bootstrap-datetimepicker.min.css">
	<script type="text/javascript" src="../../../NCProjectWeb/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../../../NCProjectWeb/js/moment.js"></script>
	
	<title>New Flight</title>
</head>
<body>
	<script> <!-- for inputs-->
		$(function () {
		$('#deptime').datetimepicker({language: 'ru'});
		$('#arrtime').datetimepicker({language: 'ru'});
		});
	</script>
	<%@ page import="entities.*" %>
	<%@ page import="java.util.ArrayList" %>
	<%@ page import = "java.util.Map" %>
	
	 <%
	 
	 	//String depAirport = new String(((String) request.getAttribute("depairport")).getBytes("ISO-8859-1"),"UTF-8");
	 	//String arrAirport = (String) request.getAttribute("arrairport");
	 
	 	ArrayList<Airline> list = (ArrayList<Airline>) request.getAttribute("airlineList");
	 	ArrayList<Aircraft> aircrList = (ArrayList<Aircraft>) request.getAttribute("aircraftList");
	 	ArrayList<Airport> airpList = (ArrayList<Airport>) request.getAttribute("airportList"); 
		Map<String, String> map = (Map<String, String>) request.getAttribute("map");
		
		String action = (String) request.getAttribute("action");	
		String formAction;
		if (action.equals("create")) {
			formAction = "createFlight";
		} else {
			formAction= "editFlight";
		} 
	%>		
	<form class="form-horizontal" method="Get" action="/NCProjectWeb/<%=formAction%>">
		<% if (action.equals("edit")) { 
			String id = (String) request.getAttribute("id");%>
			<input type="hidden" name="id" value="<%=id%>">
			<div class="controls" style="text-align: center;">
				<h3>Редактирование рейса</h3>
				<h5>Исправьте ошибки</h5>
			</div>
		<% } else {%>
			<div class="controls" style="text-align: center;">
				<h3>Создание нового рейса</h3>
				<h5>Исправьте ошибки</h5>
			</div>
		<% } %>
			<% if ((map.get("flightnumber") != null)&&(action.equals("create")))  { %>
				<div class="form-group has-error">
					<label class="col-sm-2 control-label" for="inputError">Номер рейса</label> 
					<div class="col-sm-5">
						<input type="text" class="form-control" id="inputError" name="flightnumber" value="<%=request.getAttribute("flightnumber")%>">
					</div>
					<div class="col-sm-5">
						<label class="control-label" for="inputError"><%= map.get("flightnumber").toString() %></label> 
					</div>
				</div>
			<% } else {%>
				<div class="form-group">
					<label class="col-sm-2 control-label">Номер рейса</label> 
					<div class="col-sm-5">
							<input type="text" class="form-control" name="flightnumber" value="<%=request.getAttribute("flightnumber")%>">
					</div>
				</div>
			<% } %>
		<div class="form-group">
			<label class="col-sm-2 control-label">Компания</label>
			<div class="col-sm-5">
				<select class="form-control" name="flightairline">
				<% for (int i = 0; i < list.size(); i++) {
					if (list.get(i).getAirlineName().equals(request.getAttribute("flightairline"))) {%>
					<option selected><%=list.get(i).getAirlineName()%></option>
					<% } else {%>
					<option><%=list.get(i).getAirlineName()%></option>
				<% } } %>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">Самолет</label> 
			<div class="col-sm-5">
				<select class="form-control" name="flightaircraft">
				<% for (int i = 0; i < aircrList.size(); i++) {
				if (aircrList.get(i).getAircraftType().equals(request.getAttribute("flightaircraft"))) { %>
					<option selected><%=aircrList.get(i).getAircraftType()%></option>
				<% } else {%>
					<option><%=aircrList.get(i).getAircraftType()%></option>
				<% } } %>
				</select>
			</div>
		</div>
		<hr>
		<div class="row">
			<div class="col-md-4">
				<div class="form-group">
					<div class="col-sm-6"></div>
					<div class="col-sm-6">
						<h5>Эконом класс</h5>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-6 control-label">Цены</label>
					<% if (map.get("price_ec") != null)  { %>
						<div class="col-sm-6 has-error">
							<input type="text" class="form-control" id="inputError" name="price_ec" value="<%=request.getAttribute("price_ec")%>">
						</div>
					<% } else { %>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="price_ec" value="<%=request.getAttribute("price_ec")%>">
						</div>
					<% } %>		
				</div>
				<div class="form-group">
					<label class="col-sm-6 control-label">Доступно мест</label> 
					<% if (map.get("av_ec") != null)  { %>
						<div class="col-sm-6 has-error">
							<input type="text" class="form-control" id="inputError" name="av_ec" value="<%=request.getAttribute("av_ec")%>">
						</div>
					<% } else { %>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="av_ec" value="<%=request.getAttribute("av_ec")%>">
						</div>
					<% } %>
				</div>
			</div>
			<div class="col-md-4">
				<div class="form-group">
					<div class="col-sm-3"></div>
					<div class="col-sm-6">
						<h5>Бизнес класс</h5>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3"></div>
					<% if (map.get("price_bc") != null)  { %>
						<div class="col-sm-6 has-error">
							<input type="text" class="form-control" id="inputError" name="price_bc" value="<%=request.getAttribute("price_bc")%>">
						</div>
					<% } else { %>
					<div class="col-sm-6">
						<input type="text" class="form-control" name="price_bc" value="<%=request.getAttribute("price_bc")%>">
					</div>
					<% } %>
				</div>
				<div class="form-group">
					<div class="col-sm-3"></div>
					<% if (map.get("av_bc") != null)  { %>
						<div class="col-sm-6 has-error">
							<input type="text" class="form-control" id="inputError" name="av_bc" value="<%=request.getAttribute("av_bc")%>">
						</div>
					<% } else { %>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="av_bc" value="<%=request.getAttribute("av_bc")%>">
						</div>
					<% } %>
				</div>
			</div>
			<div class="col-md-4">
				<div class="form-group">
					<div class="col-sm-6">
						<h5>Первый класс</h5>
					</div>
				</div>
				<div class="form-group">
				<% if (map.get("price_fc") != null)  { %>
					<div class="col-sm-6 has-error">
						<input type="text" class="form-control" id="inputError" name="price_fc" value="<%=request.getAttribute("price_fc")%>">
					</div>
					<div class="col-sm-6 has-error">
						<label class="control-label" for="inputError"><%=map.get("price_fc")%></label>
					</div>
				<% } else 
						if (((map.get("price_ec") != null))||((map.get("price_bc") != null))){ %>	
						<div class="col-sm-6">
							<input type="text" class="form-control" name="price_fc" value="<%=request.getAttribute("price_fc")%>">
						</div>
						<div class="col-sm-6 has-error">
							<% if (map.get("price_ec") != null)  { %>
								<label class="control-label" for="inputError"><%=map.get("price_ec")%></label>
							<% } else { %>	
								<label class="control-label" for="inputError"><%=map.get("price_bc")%></label>
							<% } %>
						</div>					
				<% } else { %>			
					<div class="col-sm-6">
						<input type="text" class="form-control" name="price_fc" value="<%=request.getAttribute("price_fc")%>">
					</div>
				<% } %>
				</div>
				<div class="form-group">
				<% if (map.get("av_fc") != null)  { %>
					<div class="col-sm-6 has-error">
						<input type="text" class="form-control" id="inputError" name="av_fc" value="<%=request.getAttribute("av_fc")%>">
					</div>
					<div class="col-sm-6 has-error">
						<label class="control-label" for="inputError"><%=map.get("av_fc")%></label>
					</div>
				<% } else 
						if (((map.get("av_ec") != null))||((map.get("av_bc") != null))){ %>
					<div class="col-sm-6">
						<input type="text" class="form-control" name="av_fc" value="<%=request.getAttribute("av_fc")%>">
					</div>
					<div class="col-sm-6 has-error">
						<% if (map.get("av_ec") != null)  { %>
							<label class="control-label" for="inputError"><%=map.get("av_ec")%></label>
						<% } else { %>
							<label class="control-label" for="inputError"><%=map.get("av_bc")%></label>
						<% } %>
					</div>
				<% } else { %>
					<div class="col-sm-6">
						<input type="text" class="form-control" name="av_fc" value="<%=request.getAttribute("av_fc")%>">
					</div>
				<% } %>
				</div>
			</div>
		</div>
		<hr>
		<div class="row">
			<div class="col-md-6">
				<div class="form-group">
					<div class="col-sm-4"></div>
					<div class="col-sm-8">
						<h5><b>Откуда</b></h5>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-4"></div>
					<div class="col-sm-8">
						<select class="form-control" name="depairport">
						<% for (int i = 0; i < airpList.size(); i++) {
							if (airpList.get(i).getAirportName().equals(request.getAttribute("depairport"))) { %>
								<option selected><%=airpList.get(i).getAirportName()%></option>
							<% } else {%>
							<option><%=airpList.get(i).getAirportName()%></option>
						<% } } %>
						</select>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-4"></div>
					<div class="col-sm-8">
						<div class="input-group date" id="deptime">
							<input class="form-control" name="deptime" type="text" value="<%=request.getAttribute("deptime")%>" autocomplete="off">
							<SPAN class="input-group-addon">
							<SPAN class="glyphicon glyphicon-calendar"></SPAN>
							</SPAN>
						</DIV>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="col-sm-2"></div>
					<div class="col-sm-8">
						<h5><b>Куда</b></h5>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-2"></div>
					<div class="col-sm-8">
						<select class="form-control" name="arrairport">
						<% 
						for (int i = 0; i < airpList.size(); i++) {
							if (airpList.get(i).getAirportName().equals(request.getAttribute("arrairport"))) {%>
							<option selected><%=airpList.get(i).getAirportName()%></option>
						<% } else { %>
							<option><%=airpList.get(i).getAirportName()%></option>
						<% } } %>
						</select>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-2"></div>
					<div class="col-sm-8">						
						<div class="input-group date" id="arrtime">
								<input class="form-control" name="arrtime" type="text" value="<%=request.getAttribute("arrtime")%>" autocomplete="off">
								<SPAN class="input-group-addon">
								<SPAN class="glyphicon glyphicon-calendar"></SPAN>
								</SPAN>
							</DIV>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-3"></div>
			<% if (action.equals("edit")) { %>
				<input type="submit" class="btn btn-default" value="Редактировать">
			<% } else {%>
				<input type="submit" class="btn btn-default" value="Создать">
			<% } %>			
			<a class="btn btn-default" href="${pageContext.request.contextPath}/admin/index.jsp" role="button">Home</a>
		</div>
	</form>
</body>
</html>